package com.naiterui.ehp.bs.cms.modules.base.controller;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.security.annotation.SysLog;
import com.naiterui.ehp.bs.cms.common.vo.PageParamsVO;
import com.naiterui.ehp.bs.cms.common.vo.PageVO;
import com.naiterui.ehp.bs.cms.modules.base.service.IDepartmentService;
import com.naiterui.ehp.bs.cms.modules.base.vo.DepartmentPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * @author 潘xin
 * @since 2021/9/10
 */
@Slf4j
@Api(tags = {SwaggerTag.CMS + SwaggerTag.BASIC_INFO})
@RequestMapping("/base/department")
@RestController
@PreAuthorize("@p.check('base:department')")
public class DepartmentController {
    @Autowired
    private IDepartmentService iDepartmentService;

    @SysLog("科室列表")
    @ApiOperation("科室列表")
    @GetMapping("/list")
    // @PreAuthorize("@p.check('base:department:list')")
    public PageVO<DepartmentPageVO> list(PageParamsVO pageParamsVO, DepartmentPageVO departmentVO) {
        return iDepartmentService.queryPage(pageParamsVO, departmentVO);
    }

    @SysLog("新增/编辑科室")
    @ApiOperation("新增/编辑科室")
    @PostMapping("/save")
    @Validated
    // @PreAuthorize("@p.check('base:department:save')")
    public void save(@RequestBody DepartmentPageVO departmentPageVO) {
        iDepartmentService.saveOrUpdate(departmentPageVO);
    }

    @SysLog("修改科室状态")
    @ApiOperation("修改科室状态")
    @PostMapping("/departmentStatus/{departmentId}/{status}")
    // @PreAuthorize("@p.check('base:department:status')")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "departmentId", value = "科室ID", dataType = "long", paramType = "path",
            required = true),
        @ApiImplicitParam(name = "status", value = "状态 0:无效，1:有效用", dataType = "String", paramType = "path",
            required = true)})
    public void hospitalStatus(@PathVariable("departmentId") Long departmentId,
        @PathVariable("status") @Max(value = 1, message = "状态不正确") @Min(value = 0, message = "状态不正确") Integer status) {
        iDepartmentService.updateDepartmentStatus(departmentId, status);
    }

}
